CC = gcc
CPPFLAGS = -g -Wall
LINKFLAGS =

OBJ_DIR = .obj
DIST_DIR = .libs

INC_PATH := -I./
INC_PATH += -I./include

SRC_FILES := $(wildcard *.c)
SRC_FILES += $(wildcard src/*.c)
SRC_FILES += $(wildcard test/*.c)

OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(SRC_FILES))

define mkdirs
	mkdir -p $(dir $(1))
endef

.DEFAULT : all

all : projm-net
#all:
	echo "[BUILD...]Projm-Net"

projm-net: dirs $(OBJS)

	$(CC) $(LINKFLAGS) $(OBJS) -o $@

dist : projm-net
	-cp projm-net $(DIST_DIR)

$(OBJ_DIR)/src/%.o:./src/%.c
	$(call mkdirs,$@)
	$(CC) $(CPPFLAGS) $(INC_PATH)  -c $^ -o $@

$(OBJ_DIR)/test/%.o:./test/%.c
	$(call mkdirs,$@)
	$(CC) $(CPPFLAGS) $(INC_PATH)  -c $^ -o $@


dirs:
	-if (test -d $(OBJ_DIR)) ; then pwd ; else mkdir -p $(OBJ_DIR); fi
	-if (test -d $(DIST_DIR)) ; then pwd ; else mkdir -p $(DIST_DIR); fi

.PHONY : clean
clean:
	-rm *.o $(OBJ_DIR)/* -rf
	-rm -rf .obj
	-rm -rf .libs
